package com.googlecode.kipler.satisfiability.completion.branching;

public class Backtracking extends AbstractBacktracking {

	public BranchingPoint apply() {
		BranchingPoint currentPoint = getCurrentPoint();
		while (!currentPoint.isBranchingPossible()
				&& currentPoint.hasPreviousBranchingPoint()) {
			currentPoint = currentPoint.previousBranchingPoint();
		}
		currentPoint.getWcs().getData().getLogger().info(
				"Backtracked to WCS " + currentPoint.getWcs().getId());
		// when we are in the initial branching point, don't forget to call the
		// backtrack method because it is necessary for some bookkeeping like
		// interpolant calculation
		if (currentPoint instanceof LinearBranchingPoint) {
			currentPoint.backtrack();
		}
		return currentPoint;
	}
}
